package cn.agiledata.bank.transaction.dao;

import java.util.List;

import cn.agiledata.bank.hibernateBean.EsPrePayTrans;
import cn.agiledata.bank.hibernateBean.SubAccount;

import com.vnv.infrastructure.logic.IPBHibernatePagingSupport;
import com.vnv.infrastructure.util.PagingResult;

public class EsPrePayTransDaoImpl extends IPBHibernatePagingSupport implements
        EsPrePayTransDao {

    public EsPrePayTrans getEsPrePayTransById(Long id) {
        return (EsPrePayTrans) getHibernateTemplate().get(EsPrePayTrans.class,
                id);
    }

    /**
     * 根据交易编号得到交易对象
     * 
     * @param transId
     * @return
     */
    public EsPrePayTrans getEsPrePayTransByTransId(String transId) {
        List list = getHibernateTemplate().find(
                "from EsPrePayTrans t where t.transId = ? ", transId);
        return list.size() == 0 ? null : (EsPrePayTrans) list.get(0);
    }
    
    public EsPrePayTrans getEsPrePayTransByDebitOrderId(SubAccount debit,
            String orderId) {
        String hql = "from EsPrePayTrans t where t.debit=? and t.orderId=?";
        List list = getHibernateTemplate().find(hql,
                new Object[] { debit, orderId });
        return list.size() == 0 ? null : (EsPrePayTrans) list.get(0);
    }

    public void saveOrUpdate(EsPrePayTrans eppt) {
        getHibernateTemplate().saveOrUpdate(eppt);
    }

    public List getEsPrePayTransListByBatchNo(String batchNo) {
        String hql = "from EsPrePayTrans t where t.batchNo = ?";
        return getHibernateTemplate().find(hql, batchNo);
    }

    public PagingResult getEsPrePayTransListByBatchNo(String batchNo,
            int pageNo, int pageSize) {
        String hql = "from EsPrePayTrans t where t.batchNo = ?";
        return findByHql(hql, new Object[] { batchNo }, pageNo, pageSize);
    }
}